﻿// -----------------------------------------------------------------------
// <copyright file="BasecampClient.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Basecamp
{
    using System;
    using DotNet37Signals.Client.Basecamp.Contracts;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class BasecampClient : IDisposable
    {
        internal Credentials Credentials { get; private set; }

        public BasecampClient(Credentials credentials)
        {
            this.Credentials = credentials;
        }

        public T GetContract<T>() where T : class, IBasecampContract
        {
            return new RestClientBase<T>(this.Credentials, "basecamphq.com", true).GetContract();
        }

        #region IDisposable Members

        public void Dispose()
        {
            this._account = null;
            this._calendarEntries = null;
            this._categories = null;
            this._comments = null;
            this._companies = null;
            this._files = null;
            this._messages = null;
            this._people = null;
            this._projects = null;
            this._timeTracking = null;
            this._todoListItems = null;
            this._todoLists = null;
        }

        #endregion

        private IAccountContract _account;
        public IAccountContract Account
        {
            get { return this._account ?? ( this._account = this.GetContract<IAccountContract>()); }
        }

        private ICalendarEntriesContract _calendarEntries;
        public ICalendarEntriesContract CalendarEntries
        {
            get { return this._calendarEntries ?? (this._calendarEntries = this.GetContract<ICalendarEntriesContract>()); }
        }

        private ICategoriesContract _categories;
        public ICategoriesContract Categories
        {
            get { return this._categories ?? (this._categories = this.GetContract<ICategoriesContract>()); }
        }

        private ICommentsContract _comments;
        public ICommentsContract Comments
        {
            get { return this._comments ?? (this._comments = this.GetContract<ICommentsContract>()); }
        }

        private ICompaniesContract _companies;
        public ICompaniesContract Companies
        {
            get { return this._companies ?? (this._companies = this.GetContract<ICompaniesContract>()); }
        }

        private IFilesContract _files;
        public IFilesContract Files
        {
            get { return this._files ?? (this._files = this.GetContract<IFilesContract>()); }
        }

        private IMessagesContract _messages;
        public IMessagesContract Messages
        {
            get { return this._messages ?? (this._messages = this.GetContract<IMessagesContract>()); }
        }

        private IPeopleContract _people;
        public IPeopleContract People
        {
            get { return this._people ?? (this._people = this.GetContract<IPeopleContract>()); }
        }

        private IProjectsContract _projects;
        public IProjectsContract Projects
        {
            get { return this._projects ?? (this._projects = this.GetContract<IProjectsContract>()); }
        }

        private ITimeTrackingContract _timeTracking;
        public ITimeTrackingContract TimeTracking
        {
            get { return this._timeTracking ?? (this._timeTracking = this.GetContract<ITimeTrackingContract>()); }
        }

        private ITodoListItemsContract _todoListItems;
        public ITodoListItemsContract TodoListItems
        {
            get { return this._todoListItems ?? (this._todoListItems = this.GetContract<ITodoListItemsContract>()); }
        }

        private ITodoListsContract _todoLists;
        public ITodoListsContract TodoLists
        {
            get { return this._todoLists ?? (this._todoLists = this.GetContract<ITodoListsContract>()); }
        }
    }
}
